/**
 * Copyright 2014-2015 www.fsfkj.com
 * All rights reserved.
 * 
 * @project
 * @author Flouny.Caesar
 * @version 1.0
 * @date 2015-09-11
 */
package com.eyaomall.wxmall.common.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * AOP 日志跟踪
 * @author Flouny.Caesar
 *
 */
@Component
@Aspect
public class TraceLogAdvice {
	
	private static Logger LOG = LoggerFactory.getLogger(TraceLogAdvice.class);
	
	private long start;
	private long end;
	
	@Pointcut("execution(public * com.eyaomall.wxmall.controller.*.*(..))")
	public void pointCut() {
		// ...
	}
	
	@Before(value="pointCut()")
	public void before(JoinPoint joinPoint) {
		start = System.currentTimeMillis();
	}
	
	@AfterReturning(value="pointCut()")
	public void afterReturning(JoinPoint joinPoint) {
		StringBuffer buffer = new StringBuffer();
		buffer.append("--- ");
		buffer.append("Request Method：");
		buffer.append(joinPoint.getTarget().getClass().getName());
		buffer.append(".");
		buffer.append(joinPoint.getSignature().getName());
		buffer.append("; ");
		buffer.append("耗时：");
		
		end = System.currentTimeMillis();
		long t = (end - start);
		buffer.append(t);
		buffer.append(" 毫秒 ---");
		
		LOG.info(buffer.toString());
	}
}